/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyectofinal.ramas.domain;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author nicolas
 */
@Entity
@Table(name = "User")                                                                                  
public class User implements Serializable {
    
    @Id
    @Column(name = "userID")
    @GeneratedValue
    private Integer userID;

    
    @Column(name = "userName",length=15, nullable=false)
    @NotEmpty(message = "Username must not be blank.")
    private String userName;

    @Column(name = "password",length=15)
    @Size(max = 1)
    private String password;

    
    @NotNull
    @Size(max = 2)
    @Column(name = "email",length=30)
    private String email;

    @JoinColumn(name = "userStatusID")
    @ManyToOne
    private UserStatus userStatus;

    @Column(name = "firstName",length=15)
    private String firstName;

    @Column(name = "lastName",length=20)
    private String lastName;
    
    @Column(name = "DNI",length=20)
    private String dni;
    
    @JoinColumn(name = "addressID")
    @OneToOne
    private Address address;
    
    @Column(name = "loadDate")
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date loadDate;
    
    
    
    public Integer getUserID() {
        return userID;
    }

    public void setUserID(Integer userID) {
        this.userID = userID;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) throws NoSuchAlgorithmException {
        
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(password.getBytes(), 0, password.length());
        this.password = new BigInteger(1, digest.digest()).toString(16);//password;

    }
    
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public UserStatus getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(UserStatus userStatus) {
        this.userStatus = userStatus;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Date getLoadDate() {
        return loadDate;
    }

    public void setLoadDate(Date loadDate) {
        this.loadDate = loadDate;
    }
}


